
module.exports = class TaskDispatcher {
  constructor (tasks) {
    this.tasks = tasks
    this.size = tasks.length
    this.taskMap = {}
    this.idleIndex = 0
  }

  getTaskInfo (index) {
    return this.tasks[index]
  }

  dispatch () {
    if (this.idleIndex < this.size) {
      const result = this.idleIndex
      this.taskMap[this.idleIndex] = true
      this.idleIndex += 1
      return result
    }
    return -1
  }
}